From 6ba3ef5d823d7ffbee86923782d65b4eb1b60668 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 29 Mar 2011 03:16:34 +0200 Subject: [PATCH] label: Add optimization for a common special case Oftentimes we want to measure a layout that is as wide or wider than the current layout's maximal width. In that case we can safely reuse the current layout. --- gtk/gtklabel.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index e9601ec1fe..d17f4d7eba 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -3044,6 +3044,7 @@ gtk_label_get_measuring_layout (GtkLabel * label, int width) { GtkLabelPrivate *priv = label->priv; + PangoRectangle rect; PangoLayout *copy; if (existing_layout != NULL) @@ -3065,6 +3066,18 @@ gtk_label_get_measuring_layout (GtkLabel * label, return priv->layout; } + /* oftentimes we want to measure a width that is far wider than the current width, + * even though the layout is not wrapped. In that case, we can just return the + * current layout, because for measuring purposes, it will be identical. + */ + pango_layout_get_extents (priv->layout, NULL, &rect); + if ((width == -1 || rect.width <= width) && + !pango_layout_is_wrapped (priv->layout)) + { + g_object_ref (priv->layout); + return priv->layout; + } + copy = pango_layout_copy (priv->layout); pango_layout_set_width (copy, width); return copy; -- 2.30.2